package com.hm_.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.hm.model.Book;

@Controller
@RequestMapping("books")
@SessionAttributes(names= {"books"},types= {ArrayList.class}) //将books设置到session作用域中
public class BooksController {
	
	private Logger logger = LoggerFactory.getLogger(BooksController.class);

	private static List<Book> books = new ArrayList<>();
    //debug
	//info
	//warning
	//error
	{
		books.add(new Book("神雕侠侣", 89.7, "渣渣"));
		books.add(new Book("绝代双骄", 99.7, "古龙"));
		books.add(new Book("隋唐英雄传", 109.7, "黄易"));
	}

	@GetMapping("all")
	public String findAll(Map<String, Object> map) {
		logger.debug("这是我写出的日志");
		map.put("books", books);
		return "bs/books";
	}

	@GetMapping("del")
	public String del(@RequestParam("name") String name) {
		books.remove(new Book(name, 0, null));
		return "redirect:all";
	}
}
